package com.cliente;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.example.conver.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import domain.AdministradorVO;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class FindLista extends Activity {
	
	ListView lista;
	Button menu;
	Controller C = new Controller();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i("start", "aca empezo");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.find_cliente_result);	
		lista = (ListView) findViewById(R.id.lista);
		menu = (Button) findViewById(R.id.menu);
		Context context=this;
		
		menu.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent main = new Intent(FindLista.this, Menu.class);
				startActivity(main);
				finish();
			}
		});
		
		//extraer datos
		SharedPreferences prefs = getSharedPreferences("session", Context.MODE_PRIVATE);
		String result=C.getLista(prefs.getString("TOKEN", "vacio"));
		
		Type listType = new TypeToken<ArrayList<domain.EncriptacionVO>>() {}.getType();
		List<domain.EncriptacionVO> listas = new Gson().fromJson(result, listType);
		
		ArrayList<String> values = new ArrayList<String>();
		for(int i =0;i<listas.size();i++){
			Log.i("lista:", "" + listas.get(i).getFecha());
			values.add(listas.get(i).getTexto() + "\n"+listas.get(i).getEncriptacion()+"\n"+listas.get(i).getFecha());	
		}
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,values);
		lista.setAdapter(adapter);
	
		
		///final ArrayAdapter adapter = new ArrayAdapter(this,
		   //     android.R.layout.simple_list_item_1, list);


	}

}
